package com.bigben.springbootshiro.regiest;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.zaxxer.hikari.util.DriverDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.HashMap;

@Configuration
public class druidConfig {

    //获取yml配置文件中的spring.datasource的配置
    @ConfigurationProperties(prefix = "spring.datasource")
    @Bean
    public DataSource dataSource(){
        return new DruidDataSource();
    }

    @Bean
    public ServletRegistrationBean statViewServlet(){
        //配置后台的账号密码
        ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");
        HashMap<String,String> initParameters=new HashMap<>();
        //配置账号 初始化密码 以及允许访问的人
        initParameters.put("loginUsername","root");
        initParameters.put("loginPassword","password");
        initParameters.put("allow","");
        bean.setInitParameters(initParameters);

        return bean;
    }
}
